package com.xing.crm.web.controller;

import com.xing.crm.model.CURDResult;
import com.xing.crm.model.CourseOrder;
import com.xing.crm.model.PageResult;
import com.xing.crm.service.CourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/courseorder")
public class CourseOrderController {

    @Autowired
    private CourseOrderService orderService;

    @RequestMapping("/save")
    @ResponseBody
    public CURDResult save(CourseOrder order){
        CURDResult result = new CURDResult();
        if(order.getId() ==null || order.getId().length()==0){
            orderService.save(order);
        }else {
            orderService.update(order);
        }

        return result;
    }




    @RequestMapping("/list")
    public String list(){
        return "courseorder/list";
    }




    @RequestMapping("/listJson")
    @ResponseBody
    public PageResult<CourseOrder> listJson(CourseOrder condition,int page,int limit){

        System.out.println(condition);
        PageResult<CourseOrder> result = orderService.findPageResult(condition,page,limit);
        return result;
    }

    @RequestMapping("/add")
    public String add(){
        return "courseorder/add";
    }

    @RequestMapping("/edit")
    public String edit(Model model,String id){
        CourseOrder order=orderService.findByOrderId(id);
        model.addAttribute("order",order);

        return "courseorder/edit";
    }

    @RequestMapping("/detail")
    public String detail(Model model, String id){
        CourseOrder order=orderService.findByOrderId(id);
        model.addAttribute("order",order);
        return "courseorder/detail";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public CURDResult detele(String id){
        CURDResult result= new CURDResult();
        orderService.deleteByOrderId(id);
        return result;
    }





}
